<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>基本数据操作 | 机器学习（常用科学计算库的使用）基础定位、目标</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-katex/katex.min.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../Pandas/section4.html" />
    
    
    <link rel="prev" href="../Pandas/section2.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="5.3"
        data-chapter-title="基本数据操作"
        data-filepath="Pandas/section3.md"
        data-basepath=".."
        data-revision="Sat Jul 20 2019 23:53:14 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        机器学习（常用科学计算库的使用）基础定位、目标
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="ml_pre/index.html">
            
                
                    <a href="../ml_pre/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        机器学习概述
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="ml_pre/section1.html">
            
                
                    <a href="../ml_pre/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        人工智能概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="ml_pre/section2.html">
            
                
                    <a href="../ml_pre/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        人工智能发展历程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="ml_pre/section3.html">
            
                
                    <a href="../ml_pre/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        人工智能主要分支
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="ml_pre/section4.html">
            
                
                    <a href="../ml_pre/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        机器学习工作流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="ml_pre/section5.html">
            
                
                    <a href="../ml_pre/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        机器学习算法分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="ml_pre/section6.html">
            
                
                    <a href="../ml_pre/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        模型评估
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="ml_pre/section7.html">
            
                
                    <a href="../ml_pre/section7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        Azure机器学习模型搭建实验
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="ml_pre/section8.html">
            
                
                    <a href="../ml_pre/section8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        深度学习简介
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="env/index.html">
            
                
                    <a href="../env/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        机器学习基础环境安装与使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="env/section1.html">
            
                
                    <a href="../env/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        库的安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="env/section2.html">
            
                
                    <a href="../env/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        jupyter notebook使用
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="Matplotlib/index.html">
            
                
                    <a href="../Matplotlib/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Matplotlib
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="Matplotlib/section1.html">
            
                
                    <a href="../Matplotlib/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Matplotlib之HelloWorld
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="Matplotlib/section2.html">
            
                
                    <a href="../Matplotlib/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        基础绘图功能 — 以折线图为例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="Matplotlib/section3.html">
            
                
                    <a href="../Matplotlib/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        常见图形绘制
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="Numpy/index.html">
            
                
                    <a href="../Numpy/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Numpy
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="Numpy/section1.html">
            
                
                    <a href="../Numpy/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        Numpy的优势
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="Numpy/section2.html">
            
                
                    <a href="../Numpy/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        N维数组-ndarray
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="Numpy/section3.html">
            
                
                    <a href="../Numpy/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        基本操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="Numpy/section4.html">
            
                
                    <a href="../Numpy/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        ndarray运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="Numpy/section5.html">
            
                
                    <a href="../Numpy/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        数组间的运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="Numpy/section6.html">
            
                
                    <a href="../Numpy/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        数学：矩阵
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="Pandas/index.html">
            
                
                    <a href="../Pandas/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        Pandas
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="Pandas/section1.html">
            
                
                    <a href="../Pandas/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        Pandas介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="Pandas/section2.html">
            
                
                    <a href="../Pandas/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        Pandas数据结构
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="5.3" data-path="Pandas/section3.html">
            
                
                    <a href="../Pandas/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        基本数据操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="Pandas/section4.html">
            
                
                    <a href="../Pandas/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        DataFrame运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="Pandas/section5.html">
            
                
                    <a href="../Pandas/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        Pandas画图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="Pandas/section6.html">
            
                
                    <a href="../Pandas/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        文件读取与存储
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="Pandas/section7.html">
            
                
                    <a href="../Pandas/section7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        高级处理-缺失值处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="Pandas/section8.html">
            
                
                    <a href="../Pandas/section8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        高级处理-数据离散化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="Pandas/section9.html">
            
                
                    <a href="../Pandas/section9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        高级处理-合并
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="Pandas/section10.html">
            
                
                    <a href="../Pandas/section10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        高级处理-交叉表与透视表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.11" data-path="Pandas/section11.html">
            
                
                    <a href="../Pandas/section11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.11.</b>
                        
                        高级处理-分组与聚合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.12" data-path="Pandas/section12.html">
            
                
                    <a href="../Pandas/section12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.12.</b>
                        
                        案例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="ReadingExtension/index.html">
            
                
                    <a href="../ReadingExtension/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        拓展知识
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="ReadingExtension/1.完整机器学习项目的流程.html">
            
                
                    <a href="../ReadingExtension/1.完整机器学习项目的流程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        完整机器学习项目的流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="ReadingExtension/2.独立同分布.html">
            
                
                    <a href="../ReadingExtension/2.独立同分布.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        独立同分布
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >机器学习（常用科学计算库的使用）基础定位、目标</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="53-&#x57FA;&#x672C;&#x6570;&#x636E;&#x64CD;&#x4F5C;">5.3 &#x57FA;&#x672C;&#x6570;&#x636E;&#x64CD;&#x4F5C;</h1>
<h2 id="&#x5B66;&#x4E60;&#x76EE;&#x6807;">&#x5B66;&#x4E60;&#x76EE;&#x6807;</h2>
<ul>
<li>&#x76EE;&#x6807;<ul>
<li>&#x8BB0;&#x5FC6;DataFrame&#x7684;&#x5F62;&#x72B6;&#x3001;&#x884C;&#x5217;&#x7D22;&#x5F15;&#x540D;&#x79F0;&#x83B7;&#x53D6;&#x7B49;&#x57FA;&#x672C;&#x5C5E;&#x6027;</li>
<li>&#x5E94;&#x7528;Series&#x548C;DataFrame&#x7684;&#x7D22;&#x5F15;&#x8FDB;&#x884C;&#x5207;&#x7247;&#x83B7;&#x53D6;</li>
<li>&#x5E94;&#x7528;sort_index&#x548C;sort_values&#x5B9E;&#x73B0;&#x7D22;&#x5F15;&#x548C;&#x503C;&#x7684;&#x6392;&#x5E8F;</li>
</ul>
</li>
</ul>
<hr>
<p>&#x4E3A;&#x4E86;&#x66F4;&#x597D;&#x7684;&#x7406;&#x89E3;&#x8FD9;&#x4E9B;&#x57FA;&#x672C;&#x64CD;&#x4F5C;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x8BFB;&#x53D6;&#x4E00;&#x4E2A;&#x771F;&#x5B9E;&#x7684;&#x80A1;&#x7968;&#x6570;&#x636E;&#x3002;&#x5173;&#x4E8E;&#x6587;&#x4EF6;&#x64CD;&#x4F5C;&#xFF0C;&#x540E;&#x9762;&#x5728;&#x4ECB;&#x7ECD;&#xFF0C;&#x8FD9;&#x91CC;&#x53EA;&#x5148;&#x7528;&#x4E00;&#x4E0B;API</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x8BFB;&#x53D6;&#x6587;&#x4EF6;</span>
data = pd.read_csv(<span class="hljs-string">&quot;./data/stock_day.csv&quot;</span>)

<span class="hljs-comment"># &#x5220;&#x9664;&#x4E00;&#x4E9B;&#x5217;&#xFF0C;&#x8BA9;&#x6570;&#x636E;&#x66F4;&#x7B80;&#x5355;&#x4E9B;&#xFF0C;&#x518D;&#x53BB;&#x505A;&#x540E;&#x9762;&#x7684;&#x64CD;&#x4F5C;</span>
data = data.drop([<span class="hljs-string">&quot;ma5&quot;</span>,<span class="hljs-string">&quot;ma10&quot;</span>,<span class="hljs-string">&quot;ma20&quot;</span>,<span class="hljs-string">&quot;v_ma5&quot;</span>,<span class="hljs-string">&quot;v_ma10&quot;</span>,<span class="hljs-string">&quot;v_ma20&quot;</span>], axis=<span class="hljs-number">1</span>)
</code></pre>
<p><img src="images/stockday.png" alt="stockday"></p>
<h2 id="1-&#x7D22;&#x5F15;&#x64CD;&#x4F5C;">1 &#x7D22;&#x5F15;&#x64CD;&#x4F5C;</h2>
<p>Numpy&#x5F53;&#x4E2D;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x8BB2;&#x8FC7;&#x4F7F;&#x7528;&#x7D22;&#x5F15;&#x9009;&#x53D6;&#x5E8F;&#x5217;&#x548C;&#x5207;&#x7247;&#x9009;&#x62E9;&#xFF0C;pandas&#x4E5F;&#x652F;&#x6301;&#x7C7B;&#x4F3C;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x5217;&#x540D;&#x3001;&#x884C;&#x540D;</p>
<p>&#x79F0;&#xFF0C;&#x751A;&#x81F3;&#x7EC4;&#x5408;&#x4F7F;&#x7528;&#x3002;</p>
<h3 id="11-&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x884C;&#x5217;&#x7D22;&#x5F15;&#x5148;&#x5217;&#x540E;&#x884C;">1.1 <strong>&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x884C;&#x5217;&#x7D22;&#x5F15;(&#x5148;&#x5217;&#x540E;&#x884C;)</strong></h3>
<p>&#x83B7;&#x53D6;&apos;2018-02-27&apos;&#x8FD9;&#x5929;&#x7684;&apos;close&apos;&#x7684;&#x7ED3;&#x679C;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x884C;&#x5217;&#x7D22;&#x5F15;&#x540D;&#x5B57;&#x7684;&#x65B9;&#x5F0F;&#xFF08;&#x5148;&#x5217;&#x540E;&#x884C;&#xFF09;</span>
data[<span class="hljs-string">&apos;open&apos;</span>][<span class="hljs-string">&apos;2018-02-27&apos;</span>]
<span class="hljs-number">23.53</span>

<span class="hljs-comment"># &#x4E0D;&#x652F;&#x6301;&#x7684;&#x64CD;&#x4F5C;</span>
<span class="hljs-comment"># &#x9519;&#x8BEF;</span>
data[<span class="hljs-string">&apos;2018-02-27&apos;</span>][<span class="hljs-string">&apos;open&apos;</span>]
<span class="hljs-comment"># &#x9519;&#x8BEF;</span>
data[:<span class="hljs-number">1</span>, :<span class="hljs-number">2</span>]
</code></pre>
<h3 id="12-&#x7ED3;&#x5408;loc&#x6216;&#x8005;iloc&#x4F7F;&#x7528;&#x7D22;&#x5F15;">1.2 <strong>&#x7ED3;&#x5408;loc&#x6216;&#x8005;iloc&#x4F7F;&#x7528;&#x7D22;&#x5F15;</strong></h3>
<p>&#x83B7;&#x53D6;&#x4ECE;&apos;2018-02-27&apos;:&apos;2018-02-22&apos;&#xFF0C;&apos;open&apos;&#x7684;&#x7ED3;&#x679C;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x4F7F;&#x7528;loc:&#x53EA;&#x80FD;&#x6307;&#x5B9A;&#x884C;&#x5217;&#x7D22;&#x5F15;&#x7684;&#x540D;&#x5B57;</span>
data.loc[<span class="hljs-string">&apos;2018-02-27&apos;</span>:<span class="hljs-string">&apos;2018-02-22&apos;</span>, <span class="hljs-string">&apos;open&apos;</span>]

<span class="hljs-number">2018</span>-<span class="hljs-number">02</span>-<span class="hljs-number">27</span>    <span class="hljs-number">23.53</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">02</span>-<span class="hljs-number">26</span>    <span class="hljs-number">22.80</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">02</span>-<span class="hljs-number">23</span>    <span class="hljs-number">22.88</span>
Name: open, dtype: float64

<span class="hljs-comment"># &#x4F7F;&#x7528;iloc&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7D22;&#x5F15;&#x7684;&#x4E0B;&#x6807;&#x53BB;&#x83B7;&#x53D6;</span>
<span class="hljs-comment"># &#x83B7;&#x53D6;&#x524D;3&#x5929;&#x6570;&#x636E;,&#x524D;5&#x5217;&#x7684;&#x7ED3;&#x679C;</span>
data.iloc[:<span class="hljs-number">3</span>, :<span class="hljs-number">5</span>]

            open    high    close    low
<span class="hljs-number">2018</span>-<span class="hljs-number">02</span>-<span class="hljs-number">27</span>    <span class="hljs-number">23.53</span>    <span class="hljs-number">25.88</span>    <span class="hljs-number">24.16</span>    <span class="hljs-number">23.53</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">02</span>-<span class="hljs-number">26</span>    <span class="hljs-number">22.80</span>    <span class="hljs-number">23.78</span>    <span class="hljs-number">23.53</span>    <span class="hljs-number">22.80</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">02</span>-<span class="hljs-number">23</span>    <span class="hljs-number">22.88</span>    <span class="hljs-number">23.37</span>    <span class="hljs-number">22.82</span>    <span class="hljs-number">22.71</span>
</code></pre>
<h3 id="13-&#x4F7F;&#x7528;ix&#x7EC4;&#x5408;&#x7D22;&#x5F15;">1.3 <strong>&#x4F7F;&#x7528;ix&#x7EC4;&#x5408;&#x7D22;&#x5F15;</strong></h3>
<blockquote>
<p>Warning:Starting in 0.20.0, the <code>.ix</code> indexer is deprecated, in favor of the more strict <code>.iloc</code> and <code>.loc</code> indexers.</p>
</blockquote>
<p>&#x83B7;&#x53D6;&#x884C;&#x7B2C;1&#x5929;&#x5230;&#x7B2C;4&#x5929;&#xFF0C;[&apos;open&apos;, &apos;close&apos;, &apos;high&apos;, &apos;low&apos;]&#x8FD9;&#x4E2A;&#x56DB;&#x4E2A;&#x6307;&#x6807;&#x7684;&#x7ED3;&#x679C;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x4F7F;&#x7528;ix&#x8FDB;&#x884C;&#x4E0B;&#x8868;&#x548C;&#x540D;&#x79F0;&#x7EC4;&#x5408;&#x505A;&#x5F15;</span>
data.ix[<span class="hljs-number">0</span>:<span class="hljs-number">4</span>, [<span class="hljs-string">&apos;open&apos;</span>, <span class="hljs-string">&apos;close&apos;</span>, <span class="hljs-string">&apos;high&apos;</span>, <span class="hljs-string">&apos;low&apos;</span>]]

<span class="hljs-comment"># &#x63A8;&#x8350;&#x4F7F;&#x7528;loc&#x548C;iloc&#x6765;&#x83B7;&#x53D6;&#x7684;&#x65B9;&#x5F0F;</span>
data.loc[data.index[<span class="hljs-number">0</span>:<span class="hljs-number">4</span>], [<span class="hljs-string">&apos;open&apos;</span>, <span class="hljs-string">&apos;close&apos;</span>, <span class="hljs-string">&apos;high&apos;</span>, <span class="hljs-string">&apos;low&apos;</span>]]
data.iloc[<span class="hljs-number">0</span>:<span class="hljs-number">4</span>, data.columns.get_indexer([<span class="hljs-string">&apos;open&apos;</span>, <span class="hljs-string">&apos;close&apos;</span>, <span class="hljs-string">&apos;high&apos;</span>, <span class="hljs-string">&apos;low&apos;</span>])]

            open    close    high    low
<span class="hljs-number">2018</span>-<span class="hljs-number">02</span>-<span class="hljs-number">27</span>    <span class="hljs-number">23.53</span>    <span class="hljs-number">24.16</span>    <span class="hljs-number">25.88</span>    <span class="hljs-number">23.53</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">02</span>-<span class="hljs-number">26</span>    <span class="hljs-number">22.80</span>    <span class="hljs-number">23.53</span>    <span class="hljs-number">23.78</span>    <span class="hljs-number">22.80</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">02</span>-<span class="hljs-number">23</span>    <span class="hljs-number">22.88</span>    <span class="hljs-number">22.82</span>    <span class="hljs-number">23.37</span>    <span class="hljs-number">22.71</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">02</span>-<span class="hljs-number">22</span>    <span class="hljs-number">22.25</span>    <span class="hljs-number">22.28</span>    <span class="hljs-number">22.76</span>    <span class="hljs-number">22.02</span>
</code></pre>
<h2 id="2-&#x8D4B;&#x503C;&#x64CD;&#x4F5C;">2 &#x8D4B;&#x503C;&#x64CD;&#x4F5C;</h2>
<p>&#x5BF9;DataFrame&#x5F53;&#x4E2D;&#x7684;close&#x5217;&#x8FDB;&#x884C;&#x91CD;&#x65B0;&#x8D4B;&#x503C;&#x4E3A;1</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x76F4;&#x63A5;&#x4FEE;&#x6539;&#x539F;&#x6765;&#x7684;&#x503C;</span>
data[<span class="hljs-string">&apos;close&apos;</span>] = <span class="hljs-number">1</span>
<span class="hljs-comment"># &#x6216;&#x8005;</span>
data.close = <span class="hljs-number">1</span>
</code></pre>
<h2 id="3-&#x6392;&#x5E8F;">3 &#x6392;&#x5E8F;</h2>
<p>&#x6392;&#x5E8F;&#x6709;&#x4E24;&#x79CD;&#x5F62;&#x5F0F;&#xFF0C;&#x4E00;&#x79CD;&#x5BF9;&#x4E8E;&#x7D22;&#x5F15;&#x8FDB;&#x884C;&#x6392;&#x5E8F;&#xFF0C;&#x4E00;&#x79CD;&#x5BF9;&#x4E8E;&#x5185;&#x5BB9;&#x8FDB;&#x884C;&#x6392;&#x5E8F;</p>
<h3 id="31-dataframe&#x6392;&#x5E8F;">3.1 DataFrame&#x6392;&#x5E8F;</h3>
<ul>
<li>&#x4F7F;&#x7528;df.sort_values(by=, ascending=)<ul>
<li>&#x5355;&#x4E2A;&#x952E;&#x6216;&#x8005;&#x591A;&#x4E2A;&#x952E;&#x8FDB;&#x884C;&#x6392;&#x5E8F;,</li>
<li>&#x53C2;&#x6570;&#xFF1A;<ul>
<li>by&#xFF1A;&#x6307;&#x5B9A;&#x6392;&#x5E8F;&#x53C2;&#x8003;&#x7684;&#x952E;</li>
<li>ascending:&#x9ED8;&#x8BA4;&#x5347;&#x5E8F;<ul>
<li>ascending=False:&#x964D;&#x5E8F;</li>
<li>ascending=True:&#x5347;&#x5E8F;</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x6309;&#x7167;&#x5F00;&#x76D8;&#x4EF7;&#x5927;&#x5C0F;&#x8FDB;&#x884C;&#x6392;&#x5E8F; , &#x4F7F;&#x7528;ascending&#x6307;&#x5B9A;&#x6309;&#x7167;&#x5927;&#x5C0F;&#x6392;&#x5E8F;</span>
data.sort_values(by=<span class="hljs-string">&quot;open&quot;</span>, ascending=<span class="hljs-keyword">True</span>).head()
</code></pre>
<p><img src="images/&#x6392;&#x5E8F;&#x4E3E;&#x4F8B;1.png" alt="image-20190624114304605"></p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x6309;&#x7167;&#x591A;&#x4E2A;&#x952E;&#x8FDB;&#x884C;&#x6392;&#x5E8F;</span>
data.sort_values(by=[<span class="hljs-string">&apos;open&apos;</span>, <span class="hljs-string">&apos;high&apos;</span>])
</code></pre>
<p><img src="images/&#x6392;&#x5E8F;&#x4E3E;&#x4F8B;2.png" alt="image-20190624114352409"></p>
<ul>
<li>&#x4F7F;&#x7528;df.sort_index&#x7ED9;&#x7D22;&#x5F15;&#x8FDB;&#x884C;&#x6392;&#x5E8F;</li>
</ul>
<p>&#x8FD9;&#x4E2A;&#x80A1;&#x7968;&#x7684;&#x65E5;&#x671F;&#x7D22;&#x5F15;&#x539F;&#x6765;&#x662F;&#x4ECE;&#x5927;&#x5230;&#x5C0F;&#xFF0C;&#x73B0;&#x5728;&#x91CD;&#x65B0;&#x6392;&#x5E8F;&#xFF0C;&#x4ECE;&#x5C0F;&#x5230;&#x5927;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x5BF9;&#x7D22;&#x5F15;&#x8FDB;&#x884C;&#x6392;&#x5E8F;</span>
data.sort_index()
</code></pre>
<p><img src="images/&#x6392;&#x5E8F;&#x4E3E;&#x4F8B;3.png" alt="image-20190624114619379"></p>
<h3 id="32-series&#x6392;&#x5E8F;">3.2 Series&#x6392;&#x5E8F;</h3>
<ul>
<li>&#x4F7F;&#x7528;series.sort_values(ascending=True)&#x8FDB;&#x884C;&#x6392;&#x5E8F;</li>
</ul>
<p>series&#x6392;&#x5E8F;&#x65F6;&#xFF0C;&#x53EA;&#x6709;&#x4E00;&#x5217;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x53C2;&#x6570;</p>
<pre><code class="lang-python">data[<span class="hljs-string">&apos;p_change&apos;</span>].sort_values(ascending=<span class="hljs-keyword">True</span>).head()

<span class="hljs-number">2015</span>-<span class="hljs-number">09</span>-<span class="hljs-number">01</span>   -<span class="hljs-number">10.03</span>
<span class="hljs-number">2015</span>-<span class="hljs-number">09</span>-<span class="hljs-number">14</span>   -<span class="hljs-number">10.02</span>
<span class="hljs-number">2016</span>-<span class="hljs-number">01</span>-<span class="hljs-number">11</span>   -<span class="hljs-number">10.02</span>
<span class="hljs-number">2015</span>-<span class="hljs-number">07</span>-<span class="hljs-number">15</span>   -<span class="hljs-number">10.02</span>
<span class="hljs-number">2015</span>-<span class="hljs-number">08</span>-<span class="hljs-number">26</span>   -<span class="hljs-number">10.01</span>
Name: p_change, dtype: float64
</code></pre>
<ul>
<li>&#x4F7F;&#x7528;series.sort_index()&#x8FDB;&#x884C;&#x6392;&#x5E8F;</li>
</ul>
<p>&#x4E0E;df&#x4E00;&#x81F4;</p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x5BF9;&#x7D22;&#x5F15;&#x8FDB;&#x884C;&#x6392;&#x5E8F;</span>
data[<span class="hljs-string">&apos;p_change&apos;</span>].sort_index().head()

<span class="hljs-number">2015</span>-<span class="hljs-number">03</span>-<span class="hljs-number">02</span>    <span class="hljs-number">2.62</span>
<span class="hljs-number">2015</span>-<span class="hljs-number">03</span>-<span class="hljs-number">03</span>    <span class="hljs-number">1.44</span>
<span class="hljs-number">2015</span>-<span class="hljs-number">03</span>-<span class="hljs-number">04</span>    <span class="hljs-number">1.57</span>
<span class="hljs-number">2015</span>-<span class="hljs-number">03</span>-<span class="hljs-number">05</span>    <span class="hljs-number">2.02</span>
<span class="hljs-number">2015</span>-<span class="hljs-number">03</span>-<span class="hljs-number">06</span>    <span class="hljs-number">8.51</span>
Name: p_change, dtype: float64
</code></pre>
<h2 id="4-&#x603B;&#x7ED3;">4 &#x603B;&#x7ED3;</h2>
<ul>
<li>1.&#x7D22;&#x5F15;&#x3010;&#x638C;&#x63E1;&#x3011;<ul>
<li>&#x76F4;&#x63A5;&#x7D22;&#x5F15; -- &#x5148;&#x5217;&#x540E;&#x884C;,&#x662F;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x7D22;&#x5F15;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x8FDB;&#x884C;&#x83B7;&#x53D6;</li>
<li>loc -- &#x5148;&#x884C;&#x540E;&#x5217;,&#x662F;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x7D22;&#x5F15;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x8FDB;&#x884C;&#x83B7;&#x53D6;</li>
<li>iloc -- &#x5148;&#x884C;&#x540E;&#x5217;,&#x662F;&#x901A;&#x8FC7;&#x4E0B;&#x6807;&#x8FDB;&#x884C;&#x7D22;&#x5F15;</li>
<li>ix -- &#x5148;&#x884C;&#x540E;&#x5217;, &#x53EF;&#x4EE5;&#x7528;&#x4E0A;&#x9762;&#x4E24;&#x79CD;&#x65B9;&#x6CD5;&#x6DF7;&#x5408;&#x8FDB;&#x884C;&#x7D22;&#x5F15;</li>
</ul>
</li>
<li>2.&#x8D4B;&#x503C;&#x3010;&#x77E5;&#x9053;&#x3011;<ul>
<li>data[&quot;&quot;] = **</li>
<li>data.<strong> = </strong></li>
</ul>
</li>
<li>3.&#x6392;&#x5E8F;&#x3010;&#x77E5;&#x9053;&#x3011;<ul>
<li>dataframe<ul>
<li>&#x5BF9;&#x8C61;.sort_values()</li>
<li>&#x5BF9;&#x8C61;.sort_index()</li>
</ul>
</li>
<li>series<ul>
<li>&#x5BF9;&#x8C61;.sort_values()</li>
<li>&#x5BF9;&#x8C61;.sort_index()</li>
</ul>
</li>
</ul>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../Pandas/section2.html" class="navigation navigation-prev " aria-label="Previous page: Pandas数据结构"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../Pandas/section4.html" class="navigation navigation-next " aria-label="Next page: DataFrame运算"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"katex":{},"expandable-chapters":{},"splitter":{},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
